-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add decoder support for pixel format BGRA & ARGB #315
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #315 +/- ##
==========================================
- Coverage 55.90% 55.37% -0.54%
==========================================
Files 54 55 +1
Lines 2277 2299 +22
==========================================
Hits 1273 1273
- Misses 903 925 +22
Partials 101 101
Continue to review full report at Codecov.
|
*(*uint32)(unsafe.Pointer(&frame[i])) = func(v uint32) uint32 { | ||
return (v & 0xFF00FF00) | (v&0xFF)<<16 | (v&0xFF0000)>>16 | ||
}(*(*uint32)(unsafe.Pointer(&frame[i]))) | ||
//frame[i], frame[i+2] = frame[i+2], frame[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like a conversion from ARGB
to GRAB
. (frame[i]
is A
and frame[i+2]
is G
in the original ARGB data)
Maybe the implementations of decodeARGB
and decodeBGRA
are swapped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it only matters to the name of the pixel format.
according to libyuv formats:
kCMPixelFormat_32ARGB = 32, FOURCC_BGRA
kCMPixelFormat_32BGRA = 'BGRA', FOURCC_ARGB
and I use the FOURCC_* naming to to name frame.FormatBGRA
and frame.FormatARGB
which results a similar mapping in avfoundation
pkg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I misread endian. (It should be little endian on x86 and ARM)
This func seems converting 0xXXYYZZWW (input) to 0xXXWWZZYY (output).
As the output byte order for image.RGBA
is RGBA order (XX=A, WW=B, ZZ=G, YY=R on little endian uint32), input byte order shoud be BGRA.
I guess
https://github.com/pion/mediadevices/pull/315/files#diff-99707109ce57457c8ab1161707d059373858d14ae66e06aed05c50501e29eaa6R148-R153
https://github.com/pion/mediadevices/pull/315/files#diff-99707109ce57457c8ab1161707d059373858d14ae66e06aed05c50501e29eaa6R179-R184
are reversed and name of decodeARGB
and decodeBGRA
should be swapped?
(I don't have any Macintosh computers, so I couldn't test it on the real environment.)
r := image.Rect(0, 0, width, height) | ||
for i := 0; i < size; i += 4 { | ||
*(*uint32)(unsafe.Pointer(&frame[i])) = bits.RotateLeft32(*(*uint32)(unsafe.Pointer(&frame[i])), -8) | ||
//frame[i], frame[i+1], frame[i+2], frame[i+3] = frame[i+1], frame[i+2], frame[i+3], frame[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BGRA
to GRAB
?
"fmt" | ||
"testing" | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have a simple test like:
mediadevices/pkg/frame/yuv_test.go
Lines 10 to 41 in dafd208
func TestDecodeYUY2(t *testing.T) { | |
const ( | |
width = 2 | |
height = 2 | |
) | |
input := []byte{ | |
// Y Cb Y Cr | |
0x01, 0x82, 0x03, 0x84, | |
0x05, 0x86, 0x07, 0x88, | |
} | |
expected := &image.YCbCr{ | |
Y: []byte{0x01, 0x03, 0x05, 0x07}, | |
YStride: width, | |
Cb: []byte{0x82, 0x86}, | |
Cr: []byte{0x84, 0x88}, | |
CStride: width / 2, | |
SubsampleRatio: image.YCbCrSubsampleRatio422, | |
Rect: image.Rect(0, 0, width, height), | |
} | |
decoder, err := NewDecoder(FormatYUY2) | |
if err != nil { | |
t.Fatal(err) | |
} | |
img, _, err := decoder.Decode(input, width, height) | |
if err != nil { | |
t.Fatal(err) | |
} | |
if !reflect.DeepEqual(expected, img) { | |
t.Errorf("Wrong decode result,\nexpected:\n%+v\ngot:\n%+v", expected, img) | |
} | |
} |
HI @zyxar, do you still want to get this in? |
Description
This PR adds decoder support for pixel format
BGRA
&ARGB
, and enables them in pkgavfoundation
.